<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 java.util.ArrayList,
                 com.scalar.forecast.commons.Constants" %>
<%@ page import="com.scalar.forecast.salesForecastEntry.forms.SalesForecastEntryForm" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User) session.getAttribute(com.scalar.forecast.commons.SessionKeys.USER_KEY); %>
<%
    boolean showConfidenceLevel = ConfigManager.getBooleanProperty(ConfigManager.FORECAST_SHOW_CONFIDENCE_LEVEL);
    boolean showPrice = ConfigManager.getBooleanProperty(ConfigManager.FORECAST_SHOW_PRICE);
%>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<SCRIPT language=JavaScript src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
<SCRIPT language=JavaScript src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<script src="<%=chipTracContext%>/jsp/includes/scripts/ajax_utils.js"></script>
<SCRIPT>
var prevPrice = 0;
var rowDataListCount = 0;
var slotDataListCount = 0;
var forecastDataListCount = 0; //count for no of salespersons
function submitPage()
{
    var form = document.salesForecastEntryForm;
    var pa = document.getElementById('errorsId');
    if (pa.innerHTML == "")
    {
        form.action.value = 'save';
        form.submit();
    }
}
function onReset()
{
    var form = document.salesForecastEntryForm;
    form.reset();
    calculateAllRunningTotals();
}
function onCancel()
{
    var form = document.salesForecastEntryForm;
    form.action.value = 'search';
    form.submit();
}
function toggle(imgCtrl, datablockId, forecastDataRowIdx)
{
    var form = document.salesForecastEntryForm;
    var pa = document.getElementById('errorsId');
    if (pa.innerHTML == "")
    {
        blockId = document.getElementById(datablockId);
        if (blockId.style.display == 'none')
        {
            blockId.style.display = 'block'
            imgCtrl.src = "<%=chipTracContext%>/jsp/includes/images/minus.gif";
            form['forecastDataList[' + forecastDataRowIdx + '].collapsed'].value = false;
        }
        else
        {
            blockId.style.display = 'none'
            imgCtrl.src = "<%=chipTracContext%>/jsp/includes/images/plus.gif";
            form['forecastDataList[' + forecastDataRowIdx + '].collapsed'].value = true;
        }
    }
}
function toggleBlock(salesPersonId, isDisplay) //if isDisplay = true then the block will be shown other wise it is shut
{
    var imgCtrl = document.getElementById('IMG' + salesPersonId);
    var blockCtrl = document.getElementById('SP' + salesPersonId);
    if (isDisplay)
    {
        blockCtrl.style.display = 'block'
        imgCtrl.src = "<%=chipTracContext%>/jsp/includes/images/minus.gif";
    }
    else
    {
        blockCtrl.style.display = 'none'
        imgCtrl.src = "<%=chipTracContext%>/jsp/includes/images/plus.gif";
    }
}
function storePrevValue(ctrl)
{
    prevPrice = ctrl.value;
}
function calculateAllRunningTotals()
{
    if ((forecastDataListCount + rowDataListCount) > 1)
    {
        for (slot = 0; slot < slotDataListCount; slot++)
        {
            calculateGrandRunningTotal(slot);
        }
    }
}
function calculateGrandRunningTotal(slotNumber)
{
    var form = document.salesForecastEntryForm;
    var grandRunningTotalCtrl;
    var grandRunningTotal = 0;
    var rowDataListRunningTotalCtrl = form["rowDataListRunningTotal[" + slotNumber + "].label"];
    if (rowDataListRunningTotalCtrl != null && typeof rowDataListRunningTotalCtrl != 'undefined')
    {
        grandRunningTotal = (rowDataListRunningTotalCtrl.value * 1);
    }
    for (i = 0; i < forecastDataListCount; i++) //running totals for subordinate salespersons
    {
        grandRunningTotal = grandRunningTotal + parseFloat(form["forecastDataList[" + i + "].runningTotal[" + slotNumber + "].label"].value);
    }
    grandRunningTotalCtrl = form["grandRunningTotal[" + slotNumber + "]"];
    if (grandRunningTotalCtrl != null && typeof grandRunningTotalCtrl != 'undefined')
    {
        if (grandRunningTotal.toFixed && <%=ConfigManager.getBooleanProperty(ConfigManager.FORECAST_SHOW_PRICE)%>)
        {
            grandRunningTotalCtrl.value = grandRunningTotal.toFixed(2);
        }
        else
        {
            grandRunningTotalCtrl.value = grandRunningTotal;
        }
    }
}
function calculateTotals()
{
    var form = document.salesForecastEntryForm;
    form.action.value = 'calculateRunningTotals';
    form.submit();
}
function showConfidenceLevelCombo(row, slot)
{
    var form = document.salesForecastEntryForm;
    comboCtrl = form['rowDataList[' + row + '].slotDataList[' + slot + '].confidenceLevel'];
    txtCtrl = form['rowDataList[' + row + '].slotDataList[' + slot + '].confLevelDisplayValue'];

    txtCtrl.style.display = 'none';
    comboCtrl.style.display = 'block';
    comboCtrl.focus();
}

function showConfidenceLevelCombo_fdata(fdataListRow, row, slot)
{
    var form = document.salesForecastEntryForm;
    comboCtrl = form['forecastDataList[' + fdataListRow + '].rowDataList[' + row + '].slotDataList[' + slot + '].confidenceLevel'];
    txtCtrl = form['forecastDataList[' + fdataListRow + '].rowDataList[' + row + '].slotDataList[' + slot + '].confLevelDisplayValue'];

    txtCtrl.style.display = 'none';
    comboCtrl.style.display = 'block';
    comboCtrl.focus();
}
function setSelectedValue(row, slot)
{
    var form = document.salesForecastEntryForm;
    comboCtrl = form['rowDataList[' + row + '].slotDataList[' + slot + '].confidenceLevel'];
    txtCtrl = form['rowDataList[' + row + '].slotDataList[' + slot + '].confLevelDisplayValue'];
    txtCtrl.value = comboCtrl.options[comboCtrl.selectedIndex].text;
}
function setSelectedValue_fdata(fdataListRow, row, slot)
{
    var form = document.salesForecastEntryForm;
    comboCtrl = form['forecastDataList[' + fdataListRow + '].rowDataList[' + row + '].slotDataList[' + slot + '].confidenceLevel'];
    txtCtrl = form['forecastDataList[' + fdataListRow + '].rowDataList[' + row + '].slotDataList[' + slot + '].confLevelDisplayValue'];
    txtCtrl.value = comboCtrl.options[comboCtrl.selectedIndex].text;
}
function hideCombo(row, slot)
{
    var form = document.salesForecastEntryForm;
    comboCtrl = form['rowDataList[' + row + '].slotDataList[' + slot + '].confidenceLevel'];
    txtCtrl = form['rowDataList[' + row + '].slotDataList[' + slot + '].confLevelDisplayValue'];
    comboCtrl.style.display = 'none';
    txtCtrl.style.display = 'block';
}
function hideCombo_fdata(fdataListRow, row, slot)
{
    var form = document.salesForecastEntryForm;
    comboCtrl = form['forecastDataList[' + fdataListRow + '].rowDataList[' + row + '].slotDataList[' + slot + '].confidenceLevel'];
    txtCtrl = form['forecastDataList[' + fdataListRow + '].rowDataList[' + row + '].slotDataList[' + slot + '].confLevelDisplayValue'];
    comboCtrl.style.display = 'none';
    txtCtrl.style.display = 'block';
}

function showBusy(isBusy)
{
    var requestStatusMsg = document.getElementById("waterfall-chart-container");
    if (isBusy)
        requestStatusMsg.innerHTML = "<font color=red>Processing...</font>"
    else
        requestStatusMsg.innerHTML = ""
}
function showWaterFallChart(projId, prodId)
{
    showBusy(true);
    var form = document.salesForecastEntryForm;
    var startMonth = form.month;
    var year = form.year;
    var showNext = form.showNext;

    var params = "action=loadWaterfallXHMTL";
    params += "&startMonth=" + startMonth;
    params += "&year=" + year;
    params += "&showNext=" + showNext;
    params += "&projId=" + projId;
    params += "&prodId=" + prodId;

    // Obtain an XMLHttpRequest instance
    req = newXMLHttpRequest();
    // Set the handler function to receive callback notifications
    // from the request object
    var handlerFunction;
    handlerFunction = getReadyStateTextHandler(req, showWaterFallChartHandler, "waterfall-chart-container");
    req.onreadystatechange = handlerFunction;
    // Open an HTTP POST connection to the shopping cart servlet.
    // Third parameter specifies request is asynchronous.
    req.open("POST", "<%=chipTracContext%>/salesForecastEntry.do", true);
    // Specify that the body of the request contains form data
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // Send form encoded data
    req.send(params);

}
    function showWaterFallChartHandler(responsetext, containerid) {
        if (req) {
            delete req;
        }

        var form = document.salesForecastEntryForm;
        var waterfallchartcontainer = document.getElementById(containerid);
        waterfallchartcontainer.innerHTML = responsetext;
        //showBusy(false);
    }
</SCRIPT>
<style>
    /* To provide freeze headers */
    thead th, thead th.locked {
        position: relative;
        cursor: default;

        border-right: 1px solid silver;
    }

    /* To provide freeze headers */
    thead th {
        top: expression(parentNode.parentNode.parentNode.parentNode.scrollTop-2); /* IE5+ only */
        z-index: 20;
    }

    /* To provide fixed columns in freeze headers will be display first */
    thead th.locked {
        z-index: 30;
    }

    /* To provide fixed columns */
    td.locked, th.locked {
        left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft); /* IE5+ only */
        position: relative;
        z-index: 10;

    }

    /* To provide fixed footer */
    tfoot tr {
        top: expression(parentNode.parentNode.parentNode.TopOfFooter); /* IE5+ only */
        position: relative;
        z-index: 20;
    }
</style>
<META content="MSHTML 6.00.2800.1458" name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginwidth="0" marginheight="0" onload="calculateAllRunningTotals()">
<!-- Top Header Start-->
<%
    String userTypeChiptrac = com.scalar.chiptrack.commons.Constants.USER_TYPE_CHIPTRAC + "";
%>
<logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
    <%@ include file="/jsp/includes/header.jsp" %>
</logic:equal>
<logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
    <%@ include file="/jsp/includes/extHeader.jsp" %>
</logic:notEqual>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><!--TBODY-->
<TBODY>
<TR>


<TD vAlign=top width=180
    background="<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif">
    <!-- Side Navigation start -->
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/marketing/marketing_menu.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/forecast/external_forecast_menu.jsp" %>
    </logic:notEqual>
    <!-- end of the side navigations -->
</TD>
<TD bgColor=#ffffff><IMG height=9
                         src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgColor=#ffffff><IMG height=480
                         src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></TD>
<TD vAlign=top width="100%"><IMG height=1
                                 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0> <BR>
<!-- from here your body starts -->

<html:form action="/salesForecastEntry" name="salesForecastEntryForm"
           type="com.scalar.forecast.salesForecastEntry.forms.SalesForecastEntryForm">
<%
    SalesForecastEntryForm form = (SalesForecastEntryForm) request.getAttribute("salesForecastEntryForm");
    boolean isSuperUser = user1.isActionAllowed(Functionality.FORECAST_ENTRY_FOR_ALL_SALES_PERSONS, User.USER_ACTION_MODIFY);
    int userSpersonId = -1;
    try {
        userSpersonId = Integer.parseInt((String) session.getAttribute(com.scalar.forecast.commons.SessionKeys.USER_SALESPERSON_ID));
    } catch (NumberFormatException e) {
    }
%>
<SCRIPT>
    slotDataListCount = <%=form.getShowNext()%>;
</SCRIPT>
<input type="hidden" name="action" value="">
<TABLE width="100%" align=center border=0>
<TBODY>
<TR>
    <TD class=NArialW align=middle colSpan=5>Sales Forecast</TD>
</TR>
<TR>
    <TD colSpan=5>&nbsp;</TD>
</TR>
<TR>
    <TD colspan='5' id='errorMessagesId'>
        <chiptrack:errors styleClass='NArialL'/>
        <chiptrack:info styleClass='NArialL'/>
        <FONT id="errorsId" color='FF0000'></FONT>
    </TD>
</TR>
<% if (!user1.isActionAllowed(Functionality.SALES_FORECAST, User.USER_ACTION_MODIFY)) {
%>
<tr>
    <td colspan=5 align='left'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %>
    </b></font></td>
</tr>
<% } %>
<!--<TR><TD colSpan=5>&nbsp;</TD></TR>-->
<TR align="right">
    <TD class="NArialL"><a href="javascript:calculateTotals()" class="link"
                           onmouseover="window.status='Click here to calculate totals';return true"
                           onmouseout="window.status='';return true" title="Click here to calculate totals"><img
            src="<%=chipTracContext%>/jsp/includes/images/calculate.gif" border='0'
            title="Click here to calculate totals"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<input type="hidden" name="month" value="<%=form.getMonth()%>">
<input type="hidden" name="year" value="<%=form.getYear()%>">
<input type="hidden" name="showNext" value="<%=form.getShowNext()%>">
<input type="hidden" name="spersonId" value="<%=form.getSpersonId()%>">
<TR>
<TD>
<!-- sales forecast entry table starts here -->
<DIV id="tbl-container"
     style="behavior:url(''); width: 800; height: 370; overflow: auto; scrollbar-base-color:#C0C0C0;">
<TABLE width="100%" border=0 cellspacing="0" id="salesForecastEntryTable">
<TBODY>
<THEAD>


<TR align=middle bgColor=#993333 class=NArialL>
    <TH rowspan="2" nowrap class='locked'><FONT style="color:#ffffff;">End Customer</FONT></TH>
    <TH rowspan="2" nowrap class='locked'><FONT style="color:#ffffff;">Project Name</FONT></TH>
    <TH rowspan="2" nowrap class='locked'><FONT style="color:#ffffff;">Product</FONT></TH>
    <% int noOfSlots = 0;
        ArrayList slotNames = (ArrayList) request.getAttribute("slotNames");
        noOfSlots = (slotNames == null) ? 0 : slotNames.size();
        for (int i = 0; i < noOfSlots; i++) {
    %>
    <TH colspan="3" nowrap><FONT style="color:#ffffff;"><%=slotNames.get(i)%>
    </FONT></TH>
    <%
        }
    %>
</TR>
<TR align=middle bgColor='#f2dbdb' class=NArialL>
    <%
        for (int i = 0; i < noOfSlots; i++) {
    %>
    <TH>QTY</TH>
    <TH>
        <%
            if (showPrice) {
        %>
        PRICE
        <%
            }
        %>
    </TH>
    <TH>
        <%
            if (showConfidenceLevel) {
        %>
        CL
        <%
            }
        %>
    </TH>
    <%
        }
    %>
</TR>
</THEAD>
        <% int rowCount = 0; boolean confidenceDisabledStatus = true;%>
<nested:iterate property="rowDataList" indexId="idx" id="rowData" type="com.scalar.forecast.salesForecastEntry.RowData">
        <% rowCount++;
                    if ( rowCount == 1 )
                    {
                        if ( isSuperUser || userSpersonId == rowData.getSalesPersonId() )
                        {
                            confidenceDisabledStatus = false;
                        }
                    }
                %>
<input type="hidden" name="rowDataList[<%=idx.intValue()%>].projId" value="<%=rowData.getProjId()%>">
<input type="hidden" name="rowDataList[<%=idx.intValue()%>].custId" value="<%=rowData.getCustId()%>">
<input type="hidden" name="rowDataList[<%=idx.intValue()%>].endCustId" value="<%=rowData.getEndCustId()%>">
<input type="hidden" name="rowDataList[<%=idx.intValue()%>].productId" value="<%=rowData.getProductId()%>">
<input type="hidden" name="rowDataList[<%=idx.intValue()%>].salesPersonId" value="<%=rowData.getSalesPersonId()%>">
<input type="hidden" name="rowDataList[<%=idx.intValue()%>].levelOrder" value="<%=rowData.getLevelOrder()%>">
<TR align=middle bgcolor="<%=(rowCount%2 == 0 ? "#DEE1E2" : "#FFFFEE")%>" class=NArialL id="rowDataList_<%=idx%>">
    <input type="hidden" name="rowDataList[<%=idx.intValue()%>].endCustomerName"
           value="<%=rowData.getEndCustomerName()%>">
    <input type="hidden" name="rowDataList[<%=idx.intValue()%>].projName" value="<%=rowData.getProjName()%>">
    <input type="hidden" name="rowDataList[<%=idx.intValue()%>].productName" value="<%=rowData.getProductName()%>">

    <TD class='locked'><FONT class="NArialL"><%=rowData.getEndCustomerName()%>
    </FONT></TD>
    <TD class='locked'><font class="NArialL"><a href="javascript:showWaterFallChart(<%=rowData.getProjId()%>, <%=rowData.getProductId()%>)"><%=rowData.getProjName()%></a>
    </FONT></TD>
    <TD class='locked' nowrap><FONT class="NArialL"><%=rowData.getProductName()%>
    </FONT></TD>
    <nested:iterate property="slotDataList" indexId="slotIdx" id="tempSlotData"
                    type="com.scalar.forecast.salesForecastEntry.SlotData">
        <input type="hidden" name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].rowId"
               value="<%=tempSlotData.getRowId()%>">
        <input type="hidden" name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].month"
               value="<%=tempSlotData.getMonth()%>">
        <input type="hidden" name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].year"
               value="<%=tempSlotData.getYear()%>">
        <input type="hidden" name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].readOnly"
               value="<%=tempSlotData.isReadOnly()%>">
        <%
            if (tempSlotData.isReadOnly()) {
        %>
        <input type="hidden" name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].qty"
               value="<%=tempSlotData.getQty()%>">
        <input type="hidden" name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].price"
               value="<%=tempSlotData.getPrice()%>">
        <TD><input type="text" size="7" class="valuetxfield"
                   name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].qty"
                   value="<%=tempSlotData.getQty()%>" DISABLED></TD>
        <TD>
            <%
                if (showPrice) {
            %>
            <input type="text" size="8" class="valuetxfield"
                   name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].price"
                   value="<%=tempSlotData.getPrice()%>" DISABLED>
            <%
                }
            %>
        </TD>
        <%
        } else {
        %>
        <TD><nested:text size="7" styleClass="valuetxfield" property="qty" maxlength="6"
                         onkeypress="javascript:allowInteger()" onfocus="javascript:this.select();"/></TD>
        <TD>
            <%
                if (showPrice) {
            %>
            <nested:text size="8" property="price" styleClass="valuetxfield" maxlength="10"
                         onkeyup="javascript:restrictAmt(this,7,2);"
                         onkeypress="javascript:restrictCharacters(this,7,2)" onkeydown="storePrevValue(this)"
                         onfocus="javascript:this.select();"/>
            <%
                }
            %>
        </TD>
        <%
            }
        %>
        <TD>
            <% if (showConfidenceLevel) {
                if (confidenceDisabledStatus || tempSlotData.isReadOnly()) {
            %>
            <input type="hidden"
                   name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].confidenceLevel"
                   value="<%=tempSlotData.getConfidenceLevel()%>">
            <input type="text" size="26"
                   name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].confLevelDisplayValue"
                   value="<%=tempSlotData.getConfLevelDisplayValue()%>" class="txfield" DISABLED>
            <%
            } else {
                String onchange = "setSelectedValue(" + idx.intValue() + "," + slotIdx.intValue() + ")";
                String onblur = "hideCombo(" + idx.intValue() + "," + slotIdx.intValue() + ")";
            %>
            <input type="text" size="26"
                   name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].confLevelDisplayValue"
                   value="<%=tempSlotData.getConfLevelDisplayValue()%>" class="txfield" style="display:block;" READONLY
                   onfocus="showConfidenceLevelCombo(<%=idx.intValue()%>,<%=slotIdx.intValue()%>)">
            <nested:select property="confidenceLevel" styleClass="valuetxfield" style="display:none;"
                           onchange="<%=onchange%>" onblur="<%=onblur%>">
                <html:option value="0.0">0%--Lead</html:option>
                <html:option value="25.0">25%--Qualified</html:option>
                <html:option value="50.0">50%--Pend Design Win</html:option>
                <html:option value="75.0">75%--Design Win</html:option>
                <html:option value="90.0">90%--Production</html:option>
                <html:option value="100.0">100%--Mass Prod</html:option>
            </nested:select>
            <%
                }
            } else {
            %>
            <input type="hidden"
                   name="rowDataList[<%=idx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].confidenceLevel"
                   value="<%=tempSlotData.getConfidenceLevel()%>">
            <%
                }
            %>

        </TD>
    </nested:iterate>
</TR>
</nested:iterate>
        <%
                if ( rowCount > 0 )
                {
            %>
<TR align=middle bgcolor="<%=((rowCount+1)%2 == 0 ? "#DEE1E2" : "#FFFFEE")%>" class=NArialL>
    <TD class="locked" colspan="3" align="right"><FONT class="NArialL">Total&nbsp;</FONT></TD>
    <nested:iterate property="rowDataListRunningTotal">
        <TD class="NArialL" colspan="3" align="left"><nested:text property="label" disabled="true"
                                                                  styleClass="valuetxfield"/></TD>
    </nested:iterate>
</TR>
        <%
                 }
             %>

<SCRIPT>
    rowDataListCount = <%=rowCount%>;
</SCRIPT>
        <% int forecastDataListCount    = 0; %>
<nested:iterate property="forecastDataList" indexId="idx" id="forecastData"
                type="com.scalar.forecast.salesForecastEntry.ForecastData">
        <% forecastDataListCount++; %>
<TR>
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].salesPersonName"
           value="<%=forecastData.getSalesPersonName()%>">
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].salesPersonId"
           value="<%=forecastData.getSalesPersonId()%>">
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].collapsed" value="<%=forecastData.isCollapsed()%>">
    <TD class="locked" colspan="<%=3+(noOfSlots*3)%>" bgcolor="#AAAAFF" align="left">
        <IMG src="<%=chipTracContext%>/jsp/includes/images/<%=(forecastData.isCollapsed() ? "plus.gif" : "minus.gif")%>"
             id='IMG<%=forecastData.getSalesPersonId()%>'
             onClick="toggle(this, 'SP<nested:write property="salesPersonId"/>', <%=idx.intValue()%>)" width=10>
        <FONT CLASS="NArialL"><%=forecastData.getSalesPersonName()%>
        </FONT>
    </TD>
</TR>
<TBODY id='SP<%=forecastData.getSalesPersonId()%>' style="display:<%=(forecastData.isCollapsed() ? "none" : "block")%>">
<% int rowDataCount = 0;
    confidenceDisabledStatus = true;%>
<nested:iterate property="rowDataList" indexId="rowDataIdx" id="rowData"
                type="com.scalar.forecast.salesForecastEntry.RowData">
    <% rowDataCount++;
        if (rowDataCount == 1) {
            if (isSuperUser || userSpersonId == rowData.getSalesPersonId()) {
                confidenceDisabledStatus = false;
            }
        }
    %>
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].projId"
           value="<%=rowData.getProjId()%>">
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].custId"
           value="<%=rowData.getCustId()%>">
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].endCustId"
           value="<%=rowData.getEndCustId()%>">
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].productId"
           value="<%=rowData.getProductId()%>">
    <input type="hidden"
           name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].salesPersonId"
           value="<%=rowData.getSalesPersonId()%>">
    <input type="hidden" name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].levelOrder"
           value="<%=rowData.getLevelOrder()%>">
    <TR align=middle bgcolor="<%=(rowDataCount%2 == 0 ? "#DEE1E2" : "#FFFFEE")%>" class=NArialL id="forecastDataListRowDataList_<%=rowDataIdx%>">
        <input type="hidden"
               name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].endCustomerName"
               value="<%=rowData.getEndCustomerName()%>">
        <input type="hidden"
               name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].projName"
               value="<%=rowData.getProjName()%>">
        <input type="hidden"
               name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].productName"
               value="<%=rowData.getProductName()%>">
        <TD class='locked'><FONT
                class="NArialL"><%=rowData.getEndCustomerName()%>
        </FONT></TD>
        <TD class='locked'><font class="NArialL"><a href="javascript:showWaterFallChart(<%=rowData.getProjId()%>, <%=rowData.getProductId()%>)"><%=rowData.getProjName()%></a>
        </FONT></TD>
        <TD class='locked' nowrap><FONT class="NArialL"><%=rowData.getProductName()%>
        </FONT></TD>
        <nested:iterate property="slotDataList" indexId="slotIdx" id="tempSlotData"
                        type="com.scalar.forecast.salesForecastEntry.SlotData">
            <input type="hidden"
                   name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].rowId"
                   value="<%=tempSlotData.getRowId()%>">
            <input type="hidden"
                   name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].month"
                   value="<%=tempSlotData.getMonth()%>">
            <input type="hidden"
                   name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].year"
                   value="<%=tempSlotData.getYear()%>">
            <input type="hidden"
                   name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].readOnly"
                   value="<%=tempSlotData.isReadOnly()%>">
            <%
                if (tempSlotData.isReadOnly()) {
            %>
            <input type="hidden"
                   name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].qty"
                   value="<%=tempSlotData.getQty()%>">
            <input type="hidden"
                   name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].price"
                   value="<%=tempSlotData.getPrice()%>">
            <TD><input type="text" size="7" class="valuetxfield"
                       name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].qty"
                       value="<%=tempSlotData.getQty()%>" DISABLED></TD>
            <TD>
                <%
                    if (showPrice) {
                %>
                <input type="text" size="8" class="valuetxfield"
                       name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].price"
                       value="<%=tempSlotData.getPrice()%>" DISABLED>
                <%
                    }
                %>
            </TD>
            <%
            } else {
            %>
            <TD><nested:text size="7" styleClass="valuetxfield" property="qty" maxlength="6"
                             onkeypress="javascript:allowInteger()" onfocus="javascript:this.select();"/></TD>
            <TD>
                <%
                    if (showPrice) {
                %>
                <nested:text size="8" property="price" styleClass="valuetxfield" maxlength="10"
                             onkeyup="javascript:restrictAmt(this,7,2);"
                             onkeypress="javascript:restrictCharacters(this,7,2)" onkeydown="storePrevValue(this)"
                             onfocus="javascript:this.select();"/>
                <%
                    }
                %>
            </TD>
            <%
                }
            %>
            <TD>
                <%
                    if (showConfidenceLevel) {
                        if (confidenceDisabledStatus == true || tempSlotData.isReadOnly()) {
                %>
                <nested:hidden property="confidenceLevel"/>
                <nested:text property="confLevelDisplayValue" size="26" styleClass="txfield" disabled="true"/>
                <%
                } else {
                %>
                <input type="text" size="26"
                       name="forecastDataList[<%=idx.intValue()%>].rowDataList[<%=rowDataIdx.intValue()%>].slotDataList[<%=slotIdx.intValue()%>].confLevelDisplayValue"
                       value="<%=tempSlotData.getConfLevelDisplayValue()%>" class="txfield" style="display:block;"
                       READONLY
                       onfocus="showConfidenceLevelCombo_fdata(<%=idx.intValue()%>,<%=rowDataIdx.intValue()%>,<%=slotIdx.intValue()%>)">
                <%
                    String onchange = "setSelectedValue_fdata(" + idx.intValue() + "," + rowDataIdx.intValue() + "," + slotIdx.intValue() + ")";
                    String onblur = "hideCombo_fdata(" + idx.intValue() + "," + rowDataIdx.intValue() + "," + slotIdx.intValue() + ")";
                %>
                <nested:select property="confidenceLevel" styleClass="valuetxfield" style="display:none;"
                               onchange="<%=onchange%>" onblur="<%=onblur%>">
                    <html:option value="0.0">0%--Lead</html:option>
                    <html:option value="25.0">25%--Qualified</html:option>
                    <html:option value="50.0">50%--Pend Design Win</html:option>
                    <html:option value="75.0">75%--Design Win</html:option>
                    <html:option value="90.0">90%--Production</html:option>
                    <html:option value="100.0">100%--Mass Prod</html:option>
                </nested:select>
                <%
                    }
                } else {
                %>
                <nested:hidden property="confidenceLevel"/>
                <%
                    }
                %>
            </TD>
        </nested:iterate>
    </TR>
</nested:iterate>
<TR align=middle bgcolor="<%=((rowDataCount+1)%2 == 0 ? "#DEE1E2" : "#FFFFEE")%>" class=NArialL>
    <TD class='locked' colspan="3" align="right"><FONT class="NArialL">Total&nbsp;</FONT></TD>
    <nested:iterate property="runningTotal">
        <TD class="NArialL" colspan="3" align="left"><nested:text property="label" disabled="true"
                                                                  styleClass="valuetxfield"/></TD>
    </nested:iterate>
</TR>
</TBODY>
</nested:iterate>
        <%
                if ( forecastDataListCount == 0 && rowCount == 0 )
                {
            %>
<TR align=middle class=NArialL>
    <TD COLSPAN='6' align='left' nowrap class='locked'><FONT color='red'>No Projects have been assigned to sales
        person(s)</FONT></TD>
</TR>
        <%
                }
                else if ( (forecastDataListCount+rowCount) > 1 )
                {
            %>
<TR align=middle bgcolor="#f2dbdb" class="NArialL">
    <TD class='locked' colspan="3" align="right"><FONT class="NArialL">Grand Total&nbsp;</FONT></TD>
    <% int i = 0;
        for (int k = 0; k < noOfSlots; k++) {
    %>
    <TD class="NArialL" colspan="3" align="left"><input type="text" name="grandRunningTotal[<%=k%>]" disabled="true"
                                                        class="valuetxfield"></TD>
    <%
        }
    %>
</TR>
        <%
                }
            %>
<SCRIPT>
    forecastDataListCount = <%=forecastDataListCount%>;
</SCRIPT>
</TBODY>
    <%-- <TR align="right">
       <TD colspan="<%=(3+(3*form.getShowNext()))%>" class="NArialL"><a href="javascript:calculateTotals()" class="link" onmouseover="window.status='Click here to calculate totals';return true" onmouseout="window.status='';return true" title="Click here to calculate totals"><img src="<%=chipTracContext%>/jsp/includes/images/calculate.gif" border='0' title="Click here to calculate totals"></a></TD>
    </TR>--%>
</TABLE>
</DIV>
</TD>
</TR>
    <%--<TR>
      <TD><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></TD>
    </TR>--%>
<TR>
    <%
        if (rowCount == 0 && forecastDataListCount == 0) //no row data to display
        {
    %>
    <TD align=middle colSpan=5>

        <A href="javascript:onCancel();"><IMG onmouseover="window.status='Click to go back';return true"
                                              title="Click here to go back"
                                              onmouseout="window.status='';return true" width="39" height="17"
                                              src="<%=chipTracContext%>/jsp/includes/images/back.gif" border=0></A>

    </TD>
    <%
    } else {
    %>
    <TD align=middle colSpan=5>
        <chiptrack:restrictedLink functionality='<%=Functionality.SALES_FORECAST%>'
                                  action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage();"
                                  onmouseover="window.status='Click to Save Forecast';return true"
                                  onmouseout="window.status='';return true">
            <IMG onmouseover="window.status='Click to Save Forecast';return true"
                 title="Click here to Save Forecast"
                 onmouseout="window.status='';return true"
                 src="<%=chipTracContext%>/jsp/includes/images/save.gif" border=0></chiptrack:restrictedLink>

        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <A href="javascript:onReset();"><IMG
                onmouseover="window.status='Click to Reset';return true"
                title="Click here to Reset"
                onmouseout="window.status='';return true" height=17
                src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width=53 border=0></A>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A
            href="javascript:onCancel();"><IMG
            onmouseover="window.status='Click to Cancel';return true"
            title="Click here to Cancel"
            onmouseout="window.status='';return true" height=17
            src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width=53
            border=0></A>
    </TD>
    <%
        }
    %>
</TR>
<tr>
   <td>
       <div id="waterfall-chart-container"></div>
   </td>
</tr>
</TBODY>
</TABLE>
<!-- Body Ends Here -->
</TD>
</TR>
</html:form>
</TBODY>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>